<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  
  <!-- Import MSXML version of base stylesheet -->
  <xsl:import href="hedge2svg-pure-msxml.xsl"/>
  
  <!-- Copy all input elements -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  
  <!-- Add proper SVG namespace to HTML element -->
  <xsl:template match="*[local-name() = 'html']">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg">
      <xsl:apply-templates select="node()|@*"/>
    </html>
  </xsl:template>
  
  <!-- Add reference for SVG viewer component at the end of head element -->
  <xsl:template match="*[local-name() = 'head']">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
      <object xmlns="http://www.w3.org/1999/xhtml" id="AdobeSVG" classid="clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2"></object>
      <xsl:processing-instruction name="import">namespace="svg" implementation="#AdobeSVG"</xsl:processing-instruction>
    </xsl:copy>
  </xsl:template>
  
  <!-- Convert hedge in <span class="hedge">...</span> into SVG -->
  <xsl:template match="*[local-name() = 'span' and @class = 'hedge']">
    <xsl:call-template name="hedge2svg">
      <xsl:with-param name="hedge" select="."/>
    </xsl:call-template>
  </xsl:template>
  
</xsl:stylesheet>
